<?php
require_once "mods/class_human.php";
class user extends human
{
    public $id;
    public $login;
    public $group;
    public $company;
    public $locale;

    function __construct($login=null)
    {
        if(!empty($login))
        {
            $this->Load($login);
        }
    }

function setLogin($login){$this->login=$login;}
function setGroup($group){$this->group=$group;}
function setCompany($company){$this->company=$company;}

    public function setLocale($locale)
    {
        switch ($locale)
        {
            case 1:
                $this->locale='ru';
                break;
            default:
                $this->locale='ua';
                break;
        }
    }

    public function setId($id)
    {
        $this->id=$id;
    }
    
function Set($id, $login,$group,$company, $locale){
    $this->setId($id);
	$this->setLogin($login);
	$this->setGroup($group);
	$this->setCompany($company);
    $this->setLocale($locale);
}

function Load($login){
global $_db;
	$sql="SELECT a.id,a.login,a.grp,a.engineer,a.contact,a.mail,b.town,b.phone,c.town,c.bank,c.phone, a.locale "
        . "FROM users AS a,engineer AS b,contact AS c "
        . "WHERE login='$login' AND a.engineer=b.fio AND a.contact=c.fio";
	$_db->query($sql);
	if($_db->rows){
		list($id, $login,$grp,$engineer,$contact,$mail,$town1,$phone1,$town2,$bank,$phone2, $locale)=$_db->row[0];
		$this->Set($id, $login, $grp, $bank, $locale);
		if ('client' == $this->group || 'vipclient' == $this->group || 'client_flm_limit' == $this->group
            || 'sdap_user' == $this->group || 'spprt' == $this->group)
        {
            parent::Set($contact,$town2,$mail,$phone2);
        }
		else
        {
            parent::Set($engineer,$town1,$mail,$phone1);
        }
	}
}
}
?>